const express = require("express");
const router = express.Router();
const createCode = require("../../../api/verify/create");
const checkCode = require("../../../api/verify/check");
router.post("/createCode", (req, res) => {
  createCode(req.body)
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
router.post("/checkCode", (req, res) => {
  let user = req.$user;
  checkCode({
    ...req.body,
    user,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
// 创建绑定手机验证码
router.post("createBindMobileCode", (req, res) => {
  let { mobile } = req.body;
  createCode({
    type: 9,
    mobile,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
// 创建绑定邮箱验证码
router.post("/createBindEmailCode", (req, res) => {
  let { email } = req.body;
  createCode({
    type: 9,
    email,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
// 创建手机注册验证码
router.post("/createMobileRegisterCode", (req, res) => {
  let { mobile } = req.body;
  createCode({
    type: 9,
    mobile,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
// 创建手机号验证码登录验证码
router.post("/createMobileLoginCode", (req, res) => {
  let { mobile } = req.body;
  createCode({
    type: 8,
    mobile,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
// 创建邮箱验证码登录验证码
router.post("/createEmailLoginCode", (req, res) => {
  let { email } = req.body;
  createCode({
    type: 10,
    email,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
// 创建手机号验证码找回密码验证码
router.post("/createMobileFindPasswordCode", (req, res) => {
  let { mobile } = req.body;
  createCode({
    type: 2,
    mobile,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
// 创建邮箱验证码找回密码
router.post("/createEmailFindPasswordCode", (req, res) => {
  let { email } = req.body;
  createCode({
    type: 7,
    email,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
// 创建邮箱注册验证码
router.post("/createEmailRegisterCode", (req, res) => {
  let { email } = req.body;
  createCode({
    type: 11,
    email,
  })
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.send(err);
    });
});
module.exports = router;
